package com.stone.business.lsap.action;

/**
 * <pre>
 * ----临时列表 Action---
 * </pre>
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.stone.business.lsap.pojo.TLsap;
import com.stone.business.lsap.service.LsapService;
import com.stone.para.IConstant;
import com.stone.sys.pojo.TBdz;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.pojo.TOrgan;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;

public class LsapListAction extends BaseListAction {

	private LsapService lsapService;
	
	public LsapService getLsapService() {
		return lsapService;
	}

	public void setLsapService(LsapService lsapService) {
		this.lsapService = lsapService;
		this.service=lsapService;
	}
	
	/** * 构造方法. */
    public LsapListAction() {
        this.entityClass = TLsap.class;
    }
	private String hiddenids;
	private List<TBdz> bdzList;
	private List<TDictionary> dydjList;
	private List<TDictionary> sblxList;
    
	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		List<Object> valsList = new ArrayList<Object>();
		String organCode = String.valueOf(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE));
		m.put("cols", "lsap");

		String conditions = "";
		
		// 状态
		if ("0".equals(super.getSearchBean().getCon20())) {
			conditions = " status = '" + super.getSearchBean().getCon20() + "'";
		} else {
			conditions = " status != '0'";
		}
		
		if ("3".equals(super.getSearchBean().getCon20())) {

			conditions += " and startdate - trunc(sysdate) = 2";

		} else if ("4".equals(super.getSearchBean().getCon20())) {

			conditions += " and startdate - trunc(sysdate) = 1";

		} else if ("5".equals(super.getSearchBean().getCon20())) {

			conditions += " and startdate - trunc(sysdate) = 0";

		}
		
		// 管理或者生产
		conditions += " and state = '" + super.getSearchBean().getCon19() + "'";
		TOrgan o  = (TOrgan)super.getSession().getAttribute(IConstant.SESSION_TORGAN);
		if (o.getOrganCode().toString().length() > 6 && !"1".equals(super.getSession().getAttribute("SESSION_ISADMIN"))) {
			conditions += " and ouid = '" + o.getOrganCode() + "'";
		}
			
		

		//----------------------查询条件---------------------
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon1())){
			conditions += " AND lsap.ouid like ? ";
			valsList.add(organCode+ "%");
		}
		
		// 开始时间
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())){
			conditions += " AND lsap.startdate like >= ?";
			valsList.add(super.getSearchBean().getCon2());
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())){
			conditions += " AND lsap.startdate like <= ?";
			valsList.add(super.getSearchBean().getCon3());
		}
		
		// 班组
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon5())){
			conditions += " AND lsap.bz like ? ";
			valsList.add("%" + super.getSearchBean().getCon5().replaceAll(",", "%") + "%");
		}
	
		m.put("conditions",conditions);
		m.put("clause"," order by lsap.id desc");
		m.put("alias", "lsap");
		m.put("vals", valsList.toArray());
		if ("0".equals(super.getSearchBean().getCon19())) {
				m.put("forward", "SC_SUCCESS");		
		} else {
			m.put("forward", "GL_SUCCESS");	
		}
		setDictionary();
		
		return m;
		
	}

	
	// 获得字典项目
	private void setDictionary() {
		
		// 变电站
		this.bdzList = lsapService.findListByHql(" from TBdz order by sortid");
		// 电压等级
		this.dydjList = lsapService.findListByHql(" from TDictionary where itemType = 'DYDJ' order by sortid");
		// 电压等级
		this.sblxList = lsapService.findListByHql(" from TDictionary where itemType = 'SBLX' order by sortid");
	}

	public List<TBdz> getBdzList() {
		return bdzList;
	}

	public List<TDictionary> getDydjList() {
		return dydjList;
	}

	public List<TDictionary> getSblxList() {
		return sblxList;
	}
	
	public String getHiddenids() {
		return hiddenids;
	}

	public void setHiddenids(String hiddenids) {
		this.hiddenids = hiddenids;
	}
	
}
